package cn.nawang.ebeim.api.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.nawang.ebeim.api.comm.BaseController;
import cn.nawang.ebeim.api.domain.User;
import cn.nawang.ebeim.api.service.HeartLogService;
import cn.nawang.ebeim.api.utils.Constant;

/**
 * @ClassName: StatisticsController
 * @Description: 统计
 * @author fanyb
 * @date Aug 7, 2015 10:28:04 AM
 * @version v1.0
 */
@RestController
public class StatisticsController extends BaseController {
  private static final Logger LOG = LoggerFactory.getLogger(StatisticsController.class);

  @Autowired
  private HeartLogService heartLogService;

  /**
   * 
   * @author fanyb
   * @Description: 获取该客户的终端存储情况
   * @param customerId 客户编号
   * @return Map 该客户的终端存储情况
   * @date Aug 11, 201511:19:29 AM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/statistics/storage", method = RequestMethod.GET)
  public Map<String, Object> findMemoryCase(HttpServletRequest request) {
    LOG.debug("findMemoryCase {}" + request);
    User user = this.getUserLoginInfo(request);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    map.put("storageCase", heartLogService.getMemoryCase(user));
    map.put("code", Constant.CODE_SUCCESS);
    LOG.debug("findMemoryCase result:" + map);
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: 获取该终端存储容量分布情况
   * @param customerId 客户编号
   * @param terminalId 终端编号
   * @return Map 该终端存储容量分布情况
   * @date Aug 11, 201511:23:08 AM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/statistics/storage/trends", method = RequestMethod.GET)
  public Map<String, Object> findTerminalMemoryCase(String terminalId, HttpServletRequest request) {
    LOG.debug("findTerminalMemoryCase {}" + terminalId, request);
    User user = this.getUserLoginInfo(request);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    map.put("terminalMemoryCase", heartLogService.getMemoryCase(user));
    // map.put("storageTrends", heartLogService.getStorageTrends(terminalId));
    map.put("code", Constant.CODE_SUCCESS);
    LOG.debug("findTerminalMemoryCase resutl:" + map);
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: 首页统计信息
   * @param request
   * @return Map<String,Object>
   * @date Oct 9, 20155:31:29 PM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/statistics/first_page", method = RequestMethod.GET)
  public Map<String, Object> findTotalMemoryCase(HttpServletRequest request) {
    LOG.debug("findHistoryExecuteDataSourceList {}" + request);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    User user = this.getUserLoginInfo(request);
    map.put("memoryCase", heartLogService.findTotalMemoryCase(user));
    map.put("storageCase", heartLogService.getMemoryCase(user));
    map.put("code", Constant.CODE_SUCCESS);
    LOG.debug("findTotalMemoryCase result:" + map);
    return map;
  }
}
